<?php
class ActiveRecord {
	/**
	 * @var bool
	 */
	private $isNew;
	
	/**
	 * @var array
	 */
	public $errors;
	
	/**
	 * 
	 */
	function __construct(){
		
	}
	
	/**
	 * @param array $attrs
	 */
	public static function findByAttribute($attrs) {
		$db = new Database();
		$result = $db->SqlBuilder
			->select(array('*'))
			->from(array(self::getTableName()))
			->where($attrs)
			->execute();
			
		if ( 0 == $result->resultRowsCount() ){
			return null;
		}
		
		
	}
	
	/**
	 * @param string $sql
	 */
	public static function findBySql( $sql ){
		
	}
	
	/**
	 * @param string $attr
	 * @param string $value
	 */
	public function __set($attr, $value) {
		
	}
	
	/**
	 * @param string $attr
	 */
	public function __get($attr) {
		
	}
	
	/**
	 * 
	 */
	public function save() {
		
	}
	
	/**
	 * @return bool
	 */
	public function isNew(){
		return $this->isNew;
	}
	
	/**
	 * This method use to tell where to get the records.
	 * By default, the class's name would be the table name.
	 * for example, if the child class named 'childClass'
	 * this function would get 'child_class' as default table.
	 * so, it's good to overwrite this method at child class.
	 * 
	 * @return string
	 * @since 0.0.0
	 */
	public function getTableName(){
		$tableName = str_split(get_class($this));
		
		foreach ( $tableName as $key => $value ){
			// convert upper case to '_{c}'
			if ( strtolower($tableName[$key]) !== $value ){
				$tableName[$key] = '_'.strtolower($tableName[$key]);
			}
		}
		
		$tableName = implode('', $tableName);
		
		return strtolower();
	}
}

class ActiveRecordColumn {
	
}